<#import "/manage/tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="订单管理">
<#-----------------------------------------------搜索表单start----------------------------------------->
<form id="searchForm" class="form-panel">
    <ul class="panel-content row">
        <li class="row">
            <div class="span8 control-group ">
                <label class="control-label">订单号：</label>

                <div>
                    <input type="text" name="id" class="input-normal" id="id"/>
                </div>
            </div>l
            <div class="span8 control-group">
                <label class="control-label">订单状态：</label>

                <div>
                    <select name="status" class="input-normal" id="status">
                        <option value="">全部</option>
                        <option value="init">未审核</option>
                        <option value="pass">已审核</option>
                        <option value="send">已发货</option>
                        <option value="sign">已签收</option>
                        <option value="cancel">已取消</option>
                        <option value="file">已归档</option>
                    </select>
                </div>
            </div>
            <div class="span8 control-group ">
                <label class="control-label">用户账号：</label>
                <div>
                    <input type="text" name="account" class="input-normal" id="account"/>
                </div>
            </div>
        </li>
        <li class="row">
            <div class="span8 control-group ">
                <label class="control-label">支付状态：</label>

                <div>
                    <select name="paystatus" class="input-normal" id="paystatus">
                        <option value="">全部</option>
                        <option value="n">未支付</option>
                        <option value="y">已支付</option>
                    </select>
                </div>
            </div>
            <div class="span8">
                <div>
                    <label class="control-label">时间范围：</label>
                    <input type="text" name="startDate" class="calendar" id="d4311"/>
                </div>
            </div>
            <div class="span8 control-group">
                <label class="control-label">退款状态：</label>

                <div>
                    <select name="refundStatus" class="input-normal" id="refundStatus">
                        <option value="">全部</option>
                        <option value="WAIT_SELLER_AGREE">等待卖家同意退款</option>
                        <option value="WAIT_BUYER_RETURN_GOODS">卖家同意退款，等待买家退货</option>
                        <option value="WAIT_SELLER_CONFIRM_GOODS">买家已退货，等待卖家收货</option>
                        <option value="REFUND_SUCCESS">退款成功，交易关闭</option>
                    </select>
                </div>
            </div>
        </li>
        <li>
            <div class="form-actions span8">
                <#if checkPrivilege("/manage/order/search") >
                    <button type="submit" class="button  button-primary">
                        查询
                    </button>
                </#if>
                <a class="button button-danger" onclick="return delFunction()">
                    删除
                </a>
            </div>
        </li>
    </ul>
</form>
<#---------------------------------------------------------搜索表单end------------------------------------------>
<div id="grid"></div>
<#---------------------------------------------------------编辑表单start---------------------------------------->
<div id="editContent" style="display: none">
    <form id="editForm"  action="${basepath}/manage/order/updateJson" method="post">

    </form>
</div>
<#---------------------------------------------------------编辑表单end------------------------------------------>
<script>
/*-------------------------------------------------------- 表格数据渲染start-----------------------------------*/
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '订单号', dataIndex: 'id', width: 100},
                {title: '订单总金额', dataIndex: 'amount', width: 100},
                {title: '商品总金额', dataIndex: 'ptotal', width: 100},
                {title: '配送费', dataIndex: 'fee', width: 100},
                {title: '数量', dataIndex: 'quantity', width: 100},
                {title: '会员', dataIndex: 'account', width: 100},
                {title: '创建日期', dataIndex: 'createdate', width: 100},
                {title: '订单状态', dataIndex: 'status', width: 100},
                {
                    title: '支付状态', dataIndex: 'paystatus', width: 100, renderer: function (data) {
                    if (data == "y") {
                        return '<img src="${basepath}/resource/images/action_check.gif">';
                    } else {
                        return '<img src="${basepath}/resource/images/action_delete.gif">';
                    }
                }
                },
                {
                    title: '操作', dataIndex: 'id', width: 200, renderer: function (value) {

                    <#if checkPrivilege("/manage/order/edit")>
                        return '<a href="${basepath}/manage/order/toEdit?id=' + value + '">编辑</a>';
                    <#else>
                        return "";
                    </#if>


                }
                }
            ];

    var store = new Store({
                url: 'loadData',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10',
                    status: $("#status").val()
                },
                pageSize: 3,	// 配置分页数目
                root: 'list',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格

                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });
    grid.render();

    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
/*---------------------------------------------------表格数据渲染 end-------------------------------------------*/
    //删除选中的记录
    function delFunction() {
        var selections = grid.getSelection();
        var ids = new Array();
        for (var i = 0; i < selections.length; i++) {
            ids[i] = selections[i].id.toString()
        }
        $.ajax({
            type: "POST",
            url: "${basepath}/manage/order/deletesJson",
            dataType: "json",
            data: {
                ids: ids
            },
            success: function (data) {
                var obj = form.serializeToObject();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        });

    }
</script>
</@page.pageBase>